

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 线程优先级的判断
 *
 * @author idea
 * @data 2019/4/28
 */
public class Lab02 {

    private static volatile boolean notStart = true;

    private static volatile boolean notStop = true;


    static class Job implements Runnable {

        private int priority;

        private long jobCount;

        public Job(int priority, int count) {
            this.priority = priority;
            this.jobCount = count;
        }

        @Override
        public void run() {
            while (notStart) {
                Thread.yield();
            }
            while (notStop) {
                Thread.yield();
                jobCount++;
            }
            Thread.yield();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        List<Job> jobs = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            int priority = i < 5 ? Thread.MIN_PRIORITY : Thread.MAX_PRIORITY;
            Job job=new Job(priority, 0);
            jobs.add(job);
            Thread thread=new Thread(job,"Thread"+i);
            thread.setPriority(priority);
            thread.start();
        }

        notStart=false;
        TimeUnit.SECONDS.sleep(10);
        for (Job job : jobs) {
            System.out.println("job priority:"+job.priority+" jobCount:"+job.jobCount);
        }
        while (true){

        }
    }
}
